package cn.edu.scau.cmi.front.dao;

import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import cn.edu.scau.cmi.ema.dao.AbstractJpaDao;
import cn.edu.scau.cmi.ema.domain.Address;
import cn.edu.scau.cmi.ema.domain.Authority;
import cn.edu.scau.cmi.ema.domain.Brand;
import cn.edu.scau.cmi.ema.domain.Food;
import cn.edu.scau.cmi.ema.domain.Producer;
import cn.edu.scau.cmi.ema.domain.Standard;

@Repository("CmiFoodDAO")
@Transactional
public class CmiFoodDAOImpl extends AbstractJpaDao<Food> implements CmiFoodDAO{
	private final static Set<Class<?>> dataTypes = new HashSet<Class<?>>(Arrays.asList(new Class<?>[] { Food.class }));

	@PersistenceContext(unitName = "ema")
	private EntityManager entityManager;

	@Override
	public Set<Food> findFoodsByNameAndProducer(String foodName, String producerName) {
		Query query = createNamedQuery("findFoodsByNameAndProducer", -1, -1, foodName, producerName);
		return new LinkedHashSet<Food>(query.getResultList());
	}

	@Override
	public EntityManager getEntityManager() {
		return entityManager;
	}

	@Override
	public Set<Class<?>> getTypes() {
		return dataTypes;
	}

	@Override
	public boolean canBeMerged(Food o) {
		return true;
	}

}